package springsecurityrabclogin;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@MapperScan(value = {"springsecurityrabclogin.mapper"})
@SpringBootApplication
public class SpringSecurityRabcLoginApplication implements CommandLineRunner {

    private final RedisTemplate redisTemplate;

    public SpringSecurityRabcLoginApplication(@Qualifier("redisTemplate") RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringSecurityRabcLoginApplication.class, args);
    }

    /**
     * 该run在springboot项目启动的时候会执行一次（仅一次）
     * 在上面的main方法之后执行之后，就会执行该run方法
     * 所以在项目中，经常用来对项目做一些初始化的工作
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        redisTemplate.setHashKeySerializer(RedisSerializer.string()); //redis的key采用string进行序列化
        redisTemplate.setHashKeySerializer(RedisSerializer.string()); //redis的hashKey采用string进行序列化
        redisTemplate.setHashValueSerializer(RedisSerializer.string()); //redis的hashValue采用string进行序列化


//        redisTemplate.setValueSerializer(RedisSerializer.json()); //redis的key采用json进行序列化,用来存储对象

    }
}
